package com.itrus.ica.ca;

import com.itrus.ica.IcaClientBase;
import com.itrus.ica.IcaConnection;
import com.itrus.ica.IcaUnavailable;
import com.itrus.raapi.info.UserInfo;
import com.itrus.util.CertUtils;
import com.itrus.util.CipherUtils;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;

public class CaCertManager extends IcaClientBase
{
  private void addFullCertInfoToProperties(FullCertInfo paramFullCertInfo, Properties paramProperties)
  {
    addUserInfoToProperties(paramFullCertInfo, paramProperties);
    ifNotNullThenAdd(paramProperties, "CERT_REQ_BUF_TYPE", paramFullCertInfo.getCertReqBufType());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_DATE", paramFullCertInfo.getCertReqDate());
    ifNotNullThenAdd(paramProperties, "CERT_APPROVE_DATE", paramFullCertInfo.getCertApproveDate());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_BUF", paramFullCertInfo.getCertReqBuffer());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_OVERRIDE_VALIDITY", paramFullCertInfo.getCertReqOverrideValidity());
    ifNotNullThenAdd(paramProperties, "CERT_SIGN_DATE", paramFullCertInfo.getCertSignDate());
    ifNotNullThenAdd(paramProperties, "CERT_SIGN_BUF", paramFullCertInfo.getCertSignBuf());
    ifNotNullThenAdd(paramProperties, "CERT_SIGN_BUF_P7", paramFullCertInfo.getCertSignBufP7());
    ifNotNullThenAdd(paramProperties, "CERT_SERIALNUMBER", paramFullCertInfo.getCertSerialNumber());
    ifNotNullThenAdd(paramProperties, "CERT_NOTBEFORE", paramFullCertInfo.getCertNotBefore());
    ifNotNullThenAdd(paramProperties, "CERT_NOTAFTER", paramFullCertInfo.getCertNotAfter());
    ifNotNullThenAdd(paramProperties, "CERT_ISSUER_HASH_MD5", paramFullCertInfo.getCertIssuerHashMd5());
    ifNotNullThenAdd(paramProperties, "CERT_SUBJECT_HASH_MD5", paramFullCertInfo.getCertSubjectHashMd5());
    ifNotNullThenAdd(paramProperties, "CERT_ISSUER_DN", paramFullCertInfo.getCertIssuerDN());
    ifNotNullThenAdd(paramProperties, "CERT_SUBJECT_DN", paramFullCertInfo.getCertSubjectDN());
    ifNotNullThenAdd(paramProperties, "ACCOUNT_ID", String.valueOf(paramFullCertInfo.getAccountId()));
    ifNotNullThenAdd(paramProperties, "ACCOUNT_HASH", paramFullCertInfo.getAccountHash());
    ifNotNullThenAdd(paramProperties, "ACCOUNT_ORGANIZATION", paramFullCertInfo.getAccountOrganization());
    ifNotNullThenAdd(paramProperties, "ACCOUNT_ORGUNIT", paramFullCertInfo.getAccountOrgUnit());
    ifNotNullThenAdd(paramProperties, "ACCOUNT_EMAIL", paramFullCertInfo.getAccountEmail());
  }

  private void addUserInfoToProperties(UserInfo paramUserInfo, Properties paramProperties)
  {
    if ((paramUserInfo.getUserOrganization() != null) && (paramUserInfo.getUserOrgUnit() != null))
      ifNotNullThenAdd(paramProperties, "ACCOUNT_HASH", CipherUtils.md5(paramUserInfo.getUserOrganization() + paramUserInfo.getUserOrgUnit()).toUpperCase());
    ifNotNullThenAdd(paramProperties, "USER_ID", String.valueOf(paramUserInfo.getUserId()));
    ifNotNullThenAdd(paramProperties, "ACCOUNT_ID", String.valueOf(paramUserInfo.getAccountId()));
    ifNotNullThenAdd(paramProperties, "USER_ID_RANDOM", paramUserInfo.getUserIdRandom());
    ifNotNullThenAdd(paramProperties, "USER_NAME", paramUserInfo.getUserName());
    ifNotNullThenAdd(paramProperties, "USER_SURNAME", paramUserInfo.getUserSurName());
    ifNotNullThenAdd(paramProperties, "CERT_SERIALNUMBER", CertUtils.getICAValidSerialNumber(paramUserInfo.getUserSerialNumber()));
    ifNotNullThenAdd(paramProperties, "USER_EMAIL", paramUserInfo.getUserEmail());
    ifNotNullThenAdd(paramProperties, "USER_ORGANIZATION", paramUserInfo.getUserOrganization());
    ifNotNullThenAdd(paramProperties, "USER_ORGUNIT", paramUserInfo.getUserOrgUnit());
    ifNotNullThenAdd(paramProperties, "USER_COUNTRY", paramUserInfo.getUserCountry());
    ifNotNullThenAdd(paramProperties, "USER_STATE", paramUserInfo.getUserState());
    ifNotNullThenAdd(paramProperties, "USER_LOCALITY", paramUserInfo.getUserLocality());
    ifNotNullThenAdd(paramProperties, "USER_STREET", paramUserInfo.getUserStreet());
    ifNotNullThenAdd(paramProperties, "USER_DNS", paramUserInfo.getUserDns());
    ifNotNullThenAdd(paramProperties, "USER_IP", paramUserInfo.getUserIp());
    ifNotNullThenAdd(paramProperties, "USER_TITLE", paramUserInfo.getUserTitle());
    ifNotNullThenAdd(paramProperties, "USER_DESCRIPTION", paramUserInfo.getUserDescription());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD1", paramUserInfo.getUserAdditionalField1());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD2", paramUserInfo.getUserAdditionalField2());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD3", paramUserInfo.getUserAdditionalField3());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD4", paramUserInfo.getUserAdditionalField4());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD5", paramUserInfo.getUserAdditionalField5());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD6", paramUserInfo.getUserAdditionalField6());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD7", paramUserInfo.getUserAdditionalField7());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD8", paramUserInfo.getUserAdditionalField8());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD9", paramUserInfo.getUserAdditionalField9());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD10", paramUserInfo.getUserAdditionalField10());
    ifNotNullThenAdd(paramProperties, "CERT_STATUS", paramUserInfo.getCertStatus());
    ifNotNullThenAdd(paramProperties, "CERT_NOTBEFORE", paramUserInfo.getCertNotBefore());
    ifNotNullThenAdd(paramProperties, "CERT_NOTAFTER", paramUserInfo.getCertNotAfter());
    ifNotNullThenAdd(paramProperties, "CERT_KMC_REQ2", paramUserInfo.getCertKmcReq2());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_OVERRIDE_VALIDITY", paramUserInfo.getCertReqOverrideValidity());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_BUF", paramUserInfo.getCertReqBuffer());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_CHALLENGE", paramUserInfo.getCertReqChallenge());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_COMMENT", paramUserInfo.getCertReqComment());
  }

  private void ifNotNullThenAdd(Properties paramProperties, String paramString1, String paramString2)
  {
    if ((paramString2 != null) && (!"".equals(paramString2)))
      paramProperties.setProperty(paramString1, paramString2);
  }

  private void setIssueCertResultCharacter(Properties paramProperties, IssueCertResult paramIssueCertResult)
  {
    paramIssueCertResult.setCertApproveDate(paramProperties.getProperty("CERT_APPROVE_DATE"));
    paramIssueCertResult.setCertIssuerDN(paramProperties.getProperty("CERT_ISSUER_DN"));
    paramIssueCertResult.setCertIssuerHashMD5(paramProperties.getProperty("CERT_ISSUER_HASH_MD5"));
    paramIssueCertResult.setCertSubjectDN(paramProperties.getProperty("CERT_SUBJECT_DN"));
    paramIssueCertResult.setCertSubjectHashMD5(paramProperties.getProperty("CERT_SUBJECT_HASH_MD5"));
    paramIssueCertResult.setCertNotBefore(paramProperties.getProperty("CERT_NOTBEFORE"));
    paramIssueCertResult.setCertNotAfter(paramProperties.getProperty("CERT_NOTAFTER"));
    paramIssueCertResult.setCertReqDate(paramProperties.getProperty("CERT_REQ_DATE"));
    paramIssueCertResult.setCertSerialNumber(paramProperties.getProperty("CERT_SERIALNUMBER"));
    paramIssueCertResult.setCertSignBuf(paramProperties.getProperty("CERT_SIGN_BUF"));
    paramIssueCertResult.setCertSignBufP7(paramProperties.getProperty("CERT_SIGN_BUF_P7"));
    paramIssueCertResult.setCertSignDate(paramProperties.getProperty("CERT_SIGN_DATE"));
    paramIssueCertResult.setCertType(paramProperties.getProperty("CERT_TYPE"));
    paramIssueCertResult.setCertReqOverrideValidity(paramProperties.getProperty("CERT_REQ_OVERRIDE_VALIDITY"));
    paramIssueCertResult.setCertIssuerHashSha1(paramProperties.getProperty("CERT_ISSUER_HASH_SHA1"));
    paramIssueCertResult.setCertSubjectHashSha1(paramProperties.getProperty("CERT_SUBJECT_HASH_SHA1"));
    paramIssueCertResult.setCertKmcReq2(paramProperties.getProperty("CERT_KMC_REQ2"));
    paramIssueCertResult.setCertKmcRep1(paramProperties.getProperty("CERT_KMC_REP1"));
    paramIssueCertResult.setCertKmcRep2(paramProperties.getProperty("CERT_KMC_REP2"));
    paramIssueCertResult.setCertKmcRep3(paramProperties.getProperty("CERT_KMC_REP3"));
  }

  public void addCaService(String paramString)
  {
    addIcaService(paramString);
  }

  public IssueCertResult issueCert(IssueCertInfo paramIssueCertInfo)
    throws IcaUnavailable
  {
    IssueCertResult localIssueCertResult = new IssueCertResult();
    if (paramIssueCertInfo.getUserOrganization() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:USER_ORGANIZATION");
      return localIssueCertResult;
    }
    if (paramIssueCertInfo.getUserOrgUnit() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:USER_ORGUNIT");
      return localIssueCertResult;
    }
    if (paramIssueCertInfo.getUserName() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:USER_NAME");
      return localIssueCertResult;
    }
    if (paramIssueCertInfo.getUserEmail() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:USER_EMAIL");
      return localIssueCertResult;
    }
    if (paramIssueCertInfo.getCertReqBuffer() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:CERT_REQ_BUF");
      return localIssueCertResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "IssueCert");
    addUserInfoToProperties(paramIssueCertInfo, localProperties1);
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localIssueCertResult.setReturnCode(l);
      if (l == 0L)
      {
        localIssueCertResult.setSuccess(true);
        setIssueCertResultCharacter(localProperties2, localIssueCertResult);
      }
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localIssueCertResult.getMessage());
      return localIssueCertResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localIssueCertResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public IssueCertResult issueDoubleCert(IssueCertInfo paramIssueCertInfo)
    throws IcaUnavailable
  {
    IssueCertResult localIssueCertResult = new IssueCertResult();
    if (paramIssueCertInfo == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:issueCertInfo");
      return localIssueCertResult;
    }
    if (paramIssueCertInfo.getCertKmcReq2() == null)
      paramIssueCertInfo.setCertKmcReq2("kmcReqVersion=20101209");
    return issueCert(paramIssueCertInfo);
  }

  public LdapPublisherResult publishUserCert(FullCertInfo paramFullCertInfo)
    throws IcaUnavailable
  {
    LdapPublisherResult localLdapPublisherResult = new LdapPublisherResult();
    if (paramFullCertInfo.getUserOrganization() == null)
    {
      localLdapPublisherResult.setReturnCode("A002");
      localLdapPublisherResult.setExtMessage("缺少必要参数:USER_ORGANIZATION");
      return localLdapPublisherResult;
    }
    if (paramFullCertInfo.getUserOrgUnit() == null)
    {
      localLdapPublisherResult.setReturnCode("A002");
      localLdapPublisherResult.setExtMessage("缺少必要参数:USER_ORGUNIT");
      return localLdapPublisherResult;
    }
    if (paramFullCertInfo.getUserName() == null)
    {
      localLdapPublisherResult.setReturnCode("A002");
      localLdapPublisherResult.setExtMessage("缺少必要参数:USER_NAME");
      return localLdapPublisherResult;
    }
    if (paramFullCertInfo.getCertSignBuf() == null)
    {
      localLdapPublisherResult.setReturnCode("A002");
      localLdapPublisherResult.setExtMessage("缺少必要参数:CERT_SIGN_BUF");
      return localLdapPublisherResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    addFullCertInfoToProperties(paramFullCertInfo, localProperties1);
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localLdapPublisherResult.setReturnCode(l);
      if (l == 0L)
        localLdapPublisherResult.setSuccess(true);
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localLdapPublisherResult.getMessage());
      return localLdapPublisherResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localLdapPublisherResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public IssueCertResult renewalCert(RenewalCertInfo paramRenewalCertInfo)
    throws IcaUnavailable
  {
    IssueCertResult localIssueCertResult = new IssueCertResult();
    if (paramRenewalCertInfo.getAccountHash() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:ACCOUNT_HASH");
      return localIssueCertResult;
    }
    if (paramRenewalCertInfo.getCertReqBuf() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:CERT_REQ_BUF");
      return localIssueCertResult;
    }
    if (paramRenewalCertInfo.getCertReqBufType() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:CERT_REQ_BUF_TYPE");
      return localIssueCertResult;
    }
    if (paramRenewalCertInfo.getOrigCertSerialNumber() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:ORIG_CERT_SERIALNUMBER");
      return localIssueCertResult;
    }
    if (paramRenewalCertInfo.getOrigCert() == null)
    {
      localIssueCertResult.setReturnCode("A002");
      localIssueCertResult.setExtMessage("缺少必要参数:ORIG_CERT");
      return localIssueCertResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "RenewalCert");
    localProperties1.setProperty("ACCOUNT_HASH", paramRenewalCertInfo.getAccountHash());
    localProperties1.setProperty("CERT_REQ_BUF", paramRenewalCertInfo.getCertReqBuf());
    localProperties1.setProperty("CERT_REQ_BUF_TYPE", paramRenewalCertInfo.getCertReqBufType());
    localProperties1.setProperty("ORIG_CERT_SERIALNUMBER", CertUtils.getICAValidSerialNumber(paramRenewalCertInfo.getOrigCertSerialNumber()));
    localProperties1.setProperty("ORIG_CERT", paramRenewalCertInfo.getOrigCert());
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localIssueCertResult.setReturnCode(l);
      if (l == 0L)
      {
        localIssueCertResult.setSuccess(true);
        setIssueCertResultCharacter(localProperties2, localIssueCertResult);
      }
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localIssueCertResult.getMessage());
      return localIssueCertResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localIssueCertResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public RevokeCertResult revokeCert(RevokeCertInfo paramRevokeCertInfo)
    throws IcaUnavailable
  {
    RevokeCertResult localRevokeCertResult = new RevokeCertResult();
    if (paramRevokeCertInfo.getAccountHash() == null)
    {
      localRevokeCertResult.setReturnCode("A002");
      localRevokeCertResult.setExtMessage("缺少必要参数:ACCOUNT_HASH");
      return localRevokeCertResult;
    }
    if (paramRevokeCertInfo.getCertSerialNumber() == null)
    {
      localRevokeCertResult.setReturnCode("A002");
      localRevokeCertResult.setExtMessage("缺少必要参数:CERT_SERIALNUMBER");
      return localRevokeCertResult;
    }
    if (paramRevokeCertInfo.getCertRevokeReason() == null)
    {
      localRevokeCertResult.setReturnCode("A002");
      localRevokeCertResult.setExtMessage("缺少必要参数:CERT_REVOKE_REASON");
      return localRevokeCertResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "RevokeCert");
    localProperties1.setProperty("ACCOUNT_HASH", paramRevokeCertInfo.getAccountHash());
    localProperties1.put("CERT_SERIALNUMBER", CertUtils.getICAValidSerialNumber(paramRevokeCertInfo.getCertSerialNumber()));
    localProperties1.put("CERT_REVOKE_REASON", paramRevokeCertInfo.getCertRevokeReason());
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localRevokeCertResult.setReturnCode(l);
      if (l == 0L)
      {
        localRevokeCertResult.setSuccess(true);
        localRevokeCertResult.setCertRevokeDate(localProperties2.getProperty("CERT_REVOKE_DATE"));
        localRevokeCertResult.setCertSerialNumber(localProperties2.getProperty("CERT_SERIALNUMBER"));
        localRevokeCertResult.setCertRevokeReason(localProperties2.getProperty("CERT_REVOKE_REASON"));
      }
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localRevokeCertResult.getMessage());
      return localRevokeCertResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localRevokeCertResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.ica.ca.CaCertManager
 * JD-Core Version:    0.6.2
 */